Dados Geoespaciais¶
Instalando o Ambiente¶
In [1]:
Copied!
!pip install geopandas shapely mapclassify libpysal splot esda pysal contextily
!pip install --upgrade pyshp
!pip install --upgrade descartes
!pip install --upgrade fiona
!pip install geopandas shapely mapclassify libpysal splot esda pysal contextily
!pip install --upgrade pyshp
!pip install --upgrade descartes
!pip install --upgrade fiona
Requirement already satisfied: geopandas in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (0.14.3)
[notice] A new release of pip is available: 24.0 -> 25.0.1 [notice] To update, run: python.exe -m pip install --upgrade pip
Requirement already satisfied: shapely in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (2.0.3) Requirement already satisfied: mapclassify in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (2.6.1) Requirement already satisfied: libpysal in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (4.10) Requirement already satisfied: splot in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (1.1.5.post1) Requirement already satisfied: esda in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (2.5.1) Requirement already satisfied: pysal in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (24.1) Requirement already satisfied: contextily in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (1.6.0) Requirement already satisfied: fiona>=1.8.21 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from geopandas) (1.9.6) Requirement already satisfied: packaging in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from geopandas) (24.0) Requirement already satisfied: pandas>=1.4.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from geopandas) (2.2.1) Requirement already satisfied: pyproj>=3.3.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from geopandas) (3.6.1) Requirement already satisfied: numpy<2,>=1.14 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from shapely) (1.26.4) Requirement already satisfied: networkx>=2.7 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from mapclassify) (3.2.1) Requirement already satisfied: scikit-learn>=1.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from mapclassify) (1.4.1.post1) Requirement already satisfied: scipy>=1.8 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from mapclassify) (1.12.0) Requirement already satisfied: beautifulsoup4>=4.10 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from libpysal) (4.12.3) Requirement already satisfied: platformdirs>=2.0.2 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from libpysal) (4.2.0) Requirement already satisfied: requests>=2.27 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from libpysal) (2.31.0) Requirement already satisfied: giddy in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from splot) (2.3.5) Requirement already satisfied: matplotlib in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from splot) (3.8.3) Requirement already satisfied: seaborn in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from splot) (0.13.2) Requirement already satisfied: spreg in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from splot) (1.4.2) Requirement already satisfied: access>=1.1.8 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (1.1.9) Requirement already satisfied: inequality>=1.0.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (1.0.1) Requirement already satisfied: pointpats>=2.2.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (2.4.0) Requirement already satisfied: segregation>=2.3.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (2.5) Requirement already satisfied: spaghetti>=1.6.6 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (1.7.5.post1) Requirement already satisfied: mgwr>=2.1.2 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (2.2.1) Requirement already satisfied: momepy>=0.5.3 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (0.7.0) Requirement already satisfied: spglm>=1.0.8 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (1.1.0) Requirement already satisfied: spint>=1.0.7 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (1.0.7) Requirement already satisfied: spvcm>=0.3.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (0.3.0) Requirement already satisfied: tobler>=0.8.2 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (0.11.2) Requirement already satisfied: spopt>=0.4.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pysal) (0.6.0) Requirement already satisfied: geopy in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from contextily) (2.4.1) Requirement already satisfied: mercantile in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from contextily) (1.2.1) Requirement already satisfied: pillow in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from contextily) (10.2.0) Requirement already satisfied: rasterio in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from contextily) (1.3.9) Requirement already satisfied: joblib in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from contextily) (1.3.2) Requirement already satisfied: xyzservices in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from contextily) (2023.10.1) Requirement already satisfied: soupsieve>1.2 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from beautifulsoup4>=4.10->libpysal) (2.5) Requirement already satisfied: attrs>=19.2.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona>=1.8.21->geopandas) (23.2.0) Requirement already satisfied: certifi in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona>=1.8.21->geopandas) (2024.2.2) Requirement already satisfied: click~=8.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona>=1.8.21->geopandas) (8.1.7) Requirement already satisfied: click-plugins>=1.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona>=1.8.21->geopandas) (1.1.1) Requirement already satisfied: cligj>=0.5 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona>=1.8.21->geopandas) (0.7.2) Requirement already satisfied: six in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona>=1.8.21->geopandas) (1.16.0) Requirement already satisfied: quantecon>=0.4.7 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from giddy->splot) (0.7.2) Requirement already satisfied: tqdm>=4.63.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from momepy>=0.5.3->pysal) (4.66.2) Requirement already satisfied: python-dateutil>=2.8.2 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pandas>=1.4.0->geopandas) (2.9.0.post0) Requirement already satisfied: pytz>=2020.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pandas>=1.4.0->geopandas) (2024.1) Requirement already satisfied: tzdata>=2022.7 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from pandas>=1.4.0->geopandas) (2024.1) Requirement already satisfied: charset-normalizer<4,>=2 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from requests>=2.27->libpysal) (3.3.2) Requirement already satisfied: idna<4,>=2.5 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from requests>=2.27->libpysal) (3.6) Requirement already satisfied: urllib3<3,>=1.21.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from requests>=2.27->libpysal) (2.2.1) Requirement already satisfied: threadpoolctl>=2.0.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from scikit-learn>=1.0->mapclassify) (3.4.0) Requirement already satisfied: deprecation in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from segregation>=2.3.1->pysal) (2.1.0) Requirement already satisfied: numba in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from segregation>=2.3.1->pysal) (0.59.1) Requirement already satisfied: rtree>=1.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from spaghetti>=1.6.6->pysal) (1.2.0) Requirement already satisfied: pulp>=2.7 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from spopt>=0.4.1->pysal) (2.8.0) Requirement already satisfied: statsmodels in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from tobler>=0.8.2->pysal) (0.14.1) Requirement already satisfied: rasterstats in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from tobler>=0.8.2->pysal) (0.19.0) Requirement already satisfied: geographiclib<3,>=1.52 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from geopy->contextily) (2.0) Requirement already satisfied: contourpy>=1.0.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->splot) (1.2.0) Requirement already satisfied: cycler>=0.10 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->splot) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->splot) (4.50.0) Requirement already satisfied: kiwisolver>=1.3.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->splot) (1.4.5) Requirement already satisfied: pyparsing>=2.3.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->splot) (3.1.2) Requirement already satisfied: affine in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from rasterio->contextily) (2.4.0) Requirement already satisfied: snuggs>=1.4.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from rasterio->contextily) (1.4.7) Requirement already satisfied: setuptools in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from rasterio->contextily) (69.2.0) Requirement already satisfied: colorama in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from click~=8.0->fiona>=1.8.21->geopandas) (0.4.6) Requirement already satisfied: sympy in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from quantecon>=0.4.7->giddy->splot) (1.12) Requirement already satisfied: llvmlite<0.43,>=0.42.0dev0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from numba->segregation>=2.3.1->pysal) (0.42.0) Requirement already satisfied: simplejson in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from rasterstats->tobler>=0.8.2->pysal) (3.19.2) Requirement already satisfied: patsy>=0.5.4 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from statsmodels->tobler>=0.8.2->pysal) (0.5.6) Requirement already satisfied: mpmath>=0.19 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from sympy->quantecon>=0.4.7->giddy->splot) (1.3.0) Requirement already satisfied: pyshp in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (2.3.1)
[notice] A new release of pip is available: 24.0 -> 25.0.1 [notice] To update, run: python.exe -m pip install --upgrade pip
Collecting descartes Downloading descartes-1.1.0-py3-none-any.whl.metadata (2.4 kB) Requirement already satisfied: matplotlib in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from descartes) (3.8.3) Requirement already satisfied: contourpy>=1.0.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->descartes) (1.2.0) Requirement already satisfied: cycler>=0.10 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->descartes) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->descartes) (4.50.0) Requirement already satisfied: kiwisolver>=1.3.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->descartes) (1.4.5) Requirement already satisfied: numpy<2,>=1.21 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->descartes) (1.26.4) Requirement already satisfied: packaging>=20.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->descartes) (24.0) Requirement already satisfied: pillow>=8 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->descartes) (10.2.0) Requirement already satisfied: pyparsing>=2.3.1 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->descartes) (3.1.2) Requirement already satisfied: python-dateutil>=2.7 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from matplotlib->descartes) (2.9.0.post0) Requirement already satisfied: six>=1.5 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from python-dateutil>=2.7->matplotlib->descartes) (1.16.0) Downloading descartes-1.1.0-py3-none-any.whl (5.8 kB) Installing collected packages: descartes Successfully installed descartes-1.1.0
[notice] A new release of pip is available: 24.0 -> 25.0.1 [notice] To update, run: python.exe -m pip install --upgrade pip
Requirement already satisfied: fiona in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (1.9.6)
Collecting fiona
Downloading fiona-1.10.1-cp312-cp312-win_amd64.whl.metadata (58 kB)
---------------------------------------- 0.0/58.1 kB ? eta -:--:--
------- -------------------------------- 10.2/58.1 kB ? eta -:--:--
------------- ------------------------ 20.5/58.1 kB 165.2 kB/s eta 0:00:01
-------------------- ----------------- 30.7/58.1 kB 217.9 kB/s eta 0:00:01
--------------------------------- ---- 51.2/58.1 kB 290.5 kB/s eta 0:00:01
-------------------------------------- 58.1/58.1 kB 278.3 kB/s eta 0:00:00
Requirement already satisfied: attrs>=19.2.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona) (23.2.0)
Requirement already satisfied: certifi in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona) (2024.2.2)
Requirement already satisfied: click~=8.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona) (8.1.7)
Requirement already satisfied: click-plugins>=1.0 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona) (1.1.1)
Requirement already satisfied: cligj>=0.5 in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from fiona) (0.7.2)
Requirement already satisfied: colorama in d:\gitrepos\curso_python_gis\.venv\lib\site-packages (from click~=8.0->fiona) (0.4.6)
Downloading fiona-1.10.1-cp312-cp312-win_amd64.whl (24.5 MB)
---------------------------------------- 0.0/24.5 MB ? eta -:--:--
---------------------------------------- 0.0/24.5 MB 2.0 MB/s eta 0:00:12
---------------------------------------- 0.2/24.5 MB 2.4 MB/s eta 0:00:11
--------------------------------------- 0.3/24.5 MB 2.4 MB/s eta 0:00:11
--------------------------------------- 0.6/24.5 MB 3.3 MB/s eta 0:00:08
- -------------------------------------- 0.8/24.5 MB 3.6 MB/s eta 0:00:07
- -------------------------------------- 0.9/24.5 MB 3.5 MB/s eta 0:00:07
- -------------------------------------- 1.1/24.5 MB 3.6 MB/s eta 0:00:07
-- ------------------------------------- 1.4/24.5 MB 3.9 MB/s eta 0:00:06
-- ------------------------------------- 1.6/24.5 MB 4.0 MB/s eta 0:00:06
--- ------------------------------------ 2.0/24.5 MB 4.4 MB/s eta 0:00:06
--- ------------------------------------ 2.4/24.5 MB 4.7 MB/s eta 0:00:05
---- ----------------------------------- 2.4/24.5 MB 4.7 MB/s eta 0:00:05
---- ----------------------------------- 2.8/24.5 MB 5.0 MB/s eta 0:00:05
----- ---------------------------------- 3.2/24.5 MB 5.1 MB/s eta 0:00:05
----- ---------------------------------- 3.6/24.5 MB 5.2 MB/s eta 0:00:05
------ --------------------------------- 4.1/24.5 MB 5.5 MB/s eta 0:00:04
------- -------------------------------- 4.5/24.5 MB 5.7 MB/s eta 0:00:04
------- -------------------------------- 4.8/24.5 MB 5.7 MB/s eta 0:00:04
-------- ------------------------------- 5.4/24.5 MB 6.0 MB/s eta 0:00:04
--------- ------------------------------ 5.9/24.5 MB 6.4 MB/s eta 0:00:03
---------- ----------------------------- 6.2/24.5 MB 6.5 MB/s eta 0:00:03
----------- ---------------------------- 6.8/24.5 MB 6.7 MB/s eta 0:00:03
----------- ---------------------------- 7.3/24.5 MB 6.8 MB/s eta 0:00:03
------------ --------------------------- 7.9/24.5 MB 7.1 MB/s eta 0:00:03
------------- -------------------------- 8.4/24.5 MB 7.3 MB/s eta 0:00:03
------------- -------------------------- 8.5/24.5 MB 7.0 MB/s eta 0:00:03
--------------- ------------------------ 9.2/24.5 MB 7.3 MB/s eta 0:00:03
---------------- ----------------------- 10.0/24.5 MB 7.7 MB/s eta 0:00:02
----------------- ---------------------- 10.8/24.5 MB 8.7 MB/s eta 0:00:02
------------------ --------------------- 11.5/24.5 MB 9.6 MB/s eta 0:00:02
-------------------- ------------------- 12.4/24.5 MB 10.7 MB/s eta 0:00:02
--------------------- ------------------ 13.3/24.5 MB 11.7 MB/s eta 0:00:01
----------------------- ---------------- 14.4/24.5 MB 13.6 MB/s eta 0:00:01
------------------------ --------------- 15.2/24.5 MB 13.9 MB/s eta 0:00:01
-------------------------- ------------- 16.3/24.5 MB 14.9 MB/s eta 0:00:01
---------------------------- ----------- 17.5/24.5 MB 16.8 MB/s eta 0:00:01
----------------------------- ---------- 17.8/24.5 MB 16.8 MB/s eta 0:00:01
----------------------------- ---------- 17.8/24.5 MB 16.8 MB/s eta 0:00:01
----------------------------- ---------- 17.8/24.5 MB 16.8 MB/s eta 0:00:01
----------------------------- ---------- 17.8/24.5 MB 16.8 MB/s eta 0:00:01
----------------------------- ---------- 17.8/24.5 MB 16.8 MB/s eta 0:00:01
----------------------------- ---------- 17.8/24.5 MB 16.8 MB/s eta 0:00:01
----------------------------- ---------- 17.8/24.5 MB 16.8 MB/s eta 0:00:01
----------------------------- ---------- 17.8/24.5 MB 16.8 MB/s eta 0:00:01
----------------------------- ---------- 17.8/24.5 MB 16.8 MB/s eta 0:00:01
----------------------------- ---------- 18.1/24.5 MB 9.6 MB/s eta 0:00:01
------------------------------- -------- 19.4/24.5 MB 10.6 MB/s eta 0:00:01
--------------------------------- ------ 20.4/24.5 MB 10.4 MB/s eta 0:00:01
---------------------------------- ----- 21.4/24.5 MB 10.6 MB/s eta 0:00:01
------------------------------------ --- 22.5/24.5 MB 10.7 MB/s eta 0:00:01
-------------------------------------- - 23.3/24.5 MB 10.7 MB/s eta 0:00:01
--------------------------------------- 24.4/24.5 MB 10.7 MB/s eta 0:00:01
--------------------------------------- 24.5/24.5 MB 10.6 MB/s eta 0:00:01
---------------------------------------- 24.5/24.5 MB 9.5 MB/s eta 0:00:00
Installing collected packages: fiona
Attempting uninstall: fiona
Found existing installation: fiona 1.9.6
Uninstalling fiona-1.9.6:
Successfully uninstalled fiona-1.9.6
Successfully installed fiona-1.10.1
[notice] A new release of pip is available: 24.0 -> 25.0.1 [notice] To update, run: python.exe -m pip install --upgrade pip
Sobre os dados¶
Baixados em https://www.ibge.gov.br/estatisticas/downloads-estatisticas.html
Dicionário de dados para Agregados preliminares por setores censitários:
Importando pacotes¶
In [2]:
Copied!
import pandas as pd
import numpy as np
import zipfile
# para gráficos
import matplotlib.pyplot as plt
import seaborn as sns
# para a análise de dados espaciais
import geopandas as gp
import mapclassify as mc
import contextily as cx
import pandas as pd
import numpy as np
import zipfile
# para gráficos
import matplotlib.pyplot as plt
import seaborn as sns
# para a análise de dados espaciais
import geopandas as gp
import mapclassify as mc
import contextily as cx
Baixando Arquivos¶
In [3]:
Copied!
!wget https://255ribeiro.github.io/curso_python_gis/geo_py/BA_Malha_Preliminar_2022.zip
!wget https://255ribeiro.github.io/curso_python_gis/geo_py/BA_Malha_Preliminar_2022.zip
--2024-03-27 13:35:54-- https://255ribeiro.github.io/curso_python_gis/geo_py/BA_Malha_Preliminar_2022.zip Resolving 255ribeiro.github.io (255ribeiro.github.io)... 185.199.108.153, 185.199.109.153, 185.199.110.153, ... Connecting to 255ribeiro.github.io (255ribeiro.github.io)|185.199.108.153|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 62263048 (59M) [application/zip] Saving to: ‘BA_Malha_Preliminar_2022.zip’ BA_Malha_Preliminar 100%[===================>] 59.38M 86.3MB/s in 0.7s 2024-03-27 13:35:54 (86.3 MB/s) - ‘BA_Malha_Preliminar_2022.zip’ saved [62263048/62263048]
Extraindo do arquivo zip¶
In [4]:
Copied!
with zipfile.ZipFile("BA_Malha_Preliminar_2022.zip", 'r') as zip_ref:
zip_ref.extractall("./BA_Malha_Preliminar_2022")
with zipfile.ZipFile("BA_Malha_Preliminar_2022.zip", 'r') as zip_ref:
zip_ref.extractall("./BA_Malha_Preliminar_2022")
Carregando GeoJson¶
In [5]:
Copied!
df_geo = gp.read_file("./BA_Malha_Preliminar_2022/BA_Malha_Preliminar_2022.json")
df_geo = gp.read_file("./BA_Malha_Preliminar_2022/BA_Malha_Preliminar_2022.json")
Informações do arquivo¶
In [6]:
Copied!
df_geo.shape
df_geo.shape
Out[6]:
(30642, 30)
In [7]:
Copied!
df_geo.info()
df_geo.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 30642 entries, 0 to 30641 Data columns (total 30 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 CD_SETOR 30642 non-null object 1 AREA_KM2 30642 non-null float64 2 CD_REGIAO 30642 non-null object 3 NM_REGIAO 30642 non-null object 4 CD_UF 30642 non-null object 5 NM_UF 30642 non-null object 6 CD_MUN 30642 non-null object 7 NM_MUN 30642 non-null object 8 CD_DIST 30642 non-null object 9 NM_DIST 30642 non-null object 10 CD_SUBDIST 30642 non-null object 11 NM_SUBDIST 5491 non-null object 12 CD_MICRO 30642 non-null object 13 NM_MICRO 30642 non-null object 14 CD_MESO 30642 non-null object 15 NM_MESO 30642 non-null object 16 CD_RGI 30642 non-null object 17 NM_RGI 30642 non-null object 18 CD_RGINT 30642 non-null object 19 NM_RGINT 30642 non-null object 20 CD_CONCURB 11112 non-null object 21 NM_CONCURB 11112 non-null object 22 v0001 30642 non-null object 23 v0002 30642 non-null object 24 v0003 30642 non-null object 25 v0004 30642 non-null object 26 v0005 30642 non-null object 27 v0006 30642 non-null object 28 v0007 30642 non-null object 29 geometry 30642 non-null geometry dtypes: float64(1), geometry(1), object(28) memory usage: 7.0+ MB
In [8]:
Copied!
df_geo.describe()
df_geo.describe()
Out[8]:
| AREA_KM2 | |
|---|---|
| count | 30642.000000 |
| mean | 18.430926 |
| std | 54.460159 |
| min | 0.001235 |
| 25% | 0.061144 |
| 50% | 0.254225 |
| 75% | 8.604529 |
| max | 1484.628804 |
In [9]:
Copied!
df_geo.head()
df_geo.head()
Out[9]:
| CD_SETOR | AREA_KM2 | CD_REGIAO | NM_REGIAO | CD_UF | NM_UF | CD_MUN | NM_MUN | CD_DIST | NM_DIST | ... | CD_CONCURB | NM_CONCURB | v0001 | v0002 | v0003 | v0004 | v0005 | v0006 | v0007 | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 290010805000001P | 1.252312 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | ... | None | None | 807 | 421 | 419 | 2 | 2.668919 | 0.000000 | 296 | POLYGON ((-41.65404 -13.25992, -41.65423 -13.2... |
| 1 | 290010805000002P | 0.258089 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | ... | None | None | 416 | 234 | 234 | 0 | 2.461538 | 11.834320 | 169 | POLYGON ((-41.66355 -13.25025, -41.66425 -13.2... |
| 2 | 290010805000003P | 0.636238 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | ... | None | None | 681 | 392 | 392 | 0 | 2.522222 | 5.185185 | 270 | POLYGON ((-41.66645 -13.25044, -41.66702 -13.2... |
| 3 | 290010805000004P | 1.395440 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | ... | None | None | 626 | 344 | 344 | 0 | 2.608333 | 2.083333 | 240 | POLYGON ((-41.66355 -13.25025, -41.66345 -13.2... |
| 4 | 290010805000005P | 1.130747 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | ... | None | None | 276 | 159 | 159 | 0 | 2.732673 | 0.990099 | 101 | POLYGON ((-41.65110 -13.25848, -41.65082 -13.2... |
5 rows × 30 columns
In [10]:
Copied!
pd.set_option('display.max_columns', None)
df_geo.head()
pd.set_option('display.max_columns', None)
df_geo.head()
Out[10]:
| CD_SETOR | AREA_KM2 | CD_REGIAO | NM_REGIAO | CD_UF | NM_UF | CD_MUN | NM_MUN | CD_DIST | NM_DIST | CD_SUBDIST | NM_SUBDIST | CD_MICRO | NM_MICRO | CD_MESO | NM_MESO | CD_RGI | NM_RGI | CD_RGINT | NM_RGINT | CD_CONCURB | NM_CONCURB | v0001 | v0002 | v0003 | v0004 | v0005 | v0006 | v0007 | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 290010805000001P | 1.252312 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | 29001080500 | None | 29023 | Seabra | 2906 | Centro Sul Baiano | 290013 | Brumado | 2904 | Vitória da Conquista | None | None | 807 | 421 | 419 | 2 | 2.668919 | 0.000000 | 296 | POLYGON ((-41.65404 -13.25992, -41.65423 -13.2... |
| 1 | 290010805000002P | 0.258089 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | 29001080500 | None | 29023 | Seabra | 2906 | Centro Sul Baiano | 290013 | Brumado | 2904 | Vitória da Conquista | None | None | 416 | 234 | 234 | 0 | 2.461538 | 11.834320 | 169 | POLYGON ((-41.66355 -13.25025, -41.66425 -13.2... |
| 2 | 290010805000003P | 0.636238 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | 29001080500 | None | 29023 | Seabra | 2906 | Centro Sul Baiano | 290013 | Brumado | 2904 | Vitória da Conquista | None | None | 681 | 392 | 392 | 0 | 2.522222 | 5.185185 | 270 | POLYGON ((-41.66645 -13.25044, -41.66702 -13.2... |
| 3 | 290010805000004P | 1.395440 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | 29001080500 | None | 29023 | Seabra | 2906 | Centro Sul Baiano | 290013 | Brumado | 2904 | Vitória da Conquista | None | None | 626 | 344 | 344 | 0 | 2.608333 | 2.083333 | 240 | POLYGON ((-41.66355 -13.25025, -41.66345 -13.2... |
| 4 | 290010805000005P | 1.130747 | 2 | Nordeste | 29 | Bahia | 2900108 | Abaíra | 290010805 | Abaíra | 29001080500 | None | 29023 | Seabra | 2906 | Centro Sul Baiano | 290013 | Brumado | 2904 | Vitória da Conquista | None | None | 276 | 159 | 159 | 0 | 2.732673 | 0.990099 | 101 | POLYGON ((-41.65110 -13.25848, -41.65082 -13.2... |
Plotagem com o geopandas¶
https://geopandas.org/en/stable/docs/user_guide/mapping.html
In [11]:
Copied!
df_geo.plot()
df_geo.plot()
Out[11]:
<Axes: >
In [12]:
Copied!
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "v0001")
fig.show()
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "v0001")
fig.show()
In [13]:
Copied!
df_geo.boundary.plot(figsize=(10,10), edgecolor="black")
df_geo.boundary.plot(figsize=(10,10), edgecolor="black")
Out[13]:
<Axes: >
In [14]:
Copied!
df_geo.boundary.plot(figsize=(10,10), edgecolor="black", lw=.5)
df_geo.boundary.plot(figsize=(10,10), edgecolor="black", lw=.5)
Out[14]:
<Axes: >
Tratando dados¶
In [15]:
Copied!
df_geo["v0001"] = df_geo["v0001"].astype(float)
df_geo["v0002"] = df_geo["v0002"].astype(float)
df_geo["v0003"] = df_geo["v0003"].astype(float)
df_geo["v0004"] = df_geo["v0004"].astype(float)
df_geo["v0005"] = df_geo["v0005"].astype(float)
df_geo["v0006"] = df_geo["v0006"].astype(float)
df_geo["v0007"] = df_geo["v0007"].astype(float)
# criado novas colunas
df_geo["desnidade_pop"] = df_geo["v0001"]/df_geo["AREA_KM2"]
df_geo["v0001"] = df_geo["v0001"].astype(float)
df_geo["v0002"] = df_geo["v0002"].astype(float)
df_geo["v0003"] = df_geo["v0003"].astype(float)
df_geo["v0004"] = df_geo["v0004"].astype(float)
df_geo["v0005"] = df_geo["v0005"].astype(float)
df_geo["v0006"] = df_geo["v0006"].astype(float)
df_geo["v0007"] = df_geo["v0007"].astype(float)
# criado novas colunas
df_geo["desnidade_pop"] = df_geo["v0001"]/df_geo["AREA_KM2"]
In [16]:
Copied!
df_geo.info()
df_geo.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 30642 entries, 0 to 30641 Data columns (total 31 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 CD_SETOR 30642 non-null object 1 AREA_KM2 30642 non-null float64 2 CD_REGIAO 30642 non-null object 3 NM_REGIAO 30642 non-null object 4 CD_UF 30642 non-null object 5 NM_UF 30642 non-null object 6 CD_MUN 30642 non-null object 7 NM_MUN 30642 non-null object 8 CD_DIST 30642 non-null object 9 NM_DIST 30642 non-null object 10 CD_SUBDIST 30642 non-null object 11 NM_SUBDIST 5491 non-null object 12 CD_MICRO 30642 non-null object 13 NM_MICRO 30642 non-null object 14 CD_MESO 30642 non-null object 15 NM_MESO 30642 non-null object 16 CD_RGI 30642 non-null object 17 NM_RGI 30642 non-null object 18 CD_RGINT 30642 non-null object 19 NM_RGINT 30642 non-null object 20 CD_CONCURB 11112 non-null object 21 NM_CONCURB 11112 non-null object 22 v0001 30642 non-null float64 23 v0002 30642 non-null float64 24 v0003 30642 non-null float64 25 v0004 30642 non-null float64 26 v0005 30642 non-null float64 27 v0006 30642 non-null float64 28 v0007 30642 non-null float64 29 geometry 30642 non-null geometry 30 desnidade_pop 30642 non-null float64 dtypes: float64(9), geometry(1), object(21) memory usage: 7.2+ MB
In [17]:
Copied!
df_geo.describe()
df_geo.describe()
Out[17]:
| AREA_KM2 | v0001 | v0002 | v0003 | v0004 | v0005 | v0006 | v0007 | desnidade_pop | |
|---|---|---|---|---|---|---|---|---|---|
| count | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 | 30642.000000 |
| mean | 18.430926 | 461.511194 | 224.417173 | 224.164447 | 0.252725 | 2.745468 | 2.032173 | 166.266497 | 6241.302646 |
| std | 54.460159 | 289.645276 | 131.152737 | 131.035016 | 1.539796 | 0.455014 | 3.254504 | 102.624350 | 10243.991791 |
| min | 0.001235 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 |
| 25% | 0.061144 | 248.000000 | 133.000000 | 133.000000 | 0.000000 | 2.571429 | 0.000000 | 90.000000 | 24.972272 |
| 50% | 0.254225 | 440.000000 | 216.000000 | 216.000000 | 0.000000 | 2.760000 | 0.921659 | 160.000000 | 1692.239809 |
| 75% | 8.604529 | 629.000000 | 298.000000 | 298.000000 | 0.000000 | 2.956522 | 3.225806 | 228.000000 | 8179.894673 |
| max | 1484.628804 | 4253.000000 | 2170.000000 | 2170.000000 | 102.000000 | 8.000000 | 100.000000 | 1397.000000 | 171696.149844 |
In [19]:
Copied!
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
legend_kwds={"title": "Habitantes por km²"}
)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
legend_kwds={"title": "Habitantes por km²"}
)
Ajustes de color maps¶
color maps padrão https://matplotlib.org/stable/users/explain/colors/colormaps.html
In [20]:
Copied!
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap='viridis',
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap='viridis',
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
Cmaps customizados¶
https://matplotlib.org/stable/gallery/color/named_colors.html
In [21]:
Copied!
from matplotlib import colors as mcolors
c_list = ["darkred","red","orangered", "salmon","mistyrose"]
c_map = mcolors.ListedColormap(c_list)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap=c_map,
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
from matplotlib import colors as mcolors
c_list = ["darkred","red","orangered", "salmon","mistyrose"]
c_map = mcolors.ListedColormap(c_list)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap=c_map,
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
usando seletores de cores da web https://coolors.co/
In [22]:
Copied!
c_list = ["#271f30","#6c5a49","#c8ad55","#9bc59d","#d0fcb3"]
#c_list.reverse()
# for i in range(len(c_list)):
# if c_list[i][0]!= "#":
# c_list[i] = "#" + c_list[i]
print(c_list)
c_map = mcolors.ListedColormap(c_list)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap=c_map,
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
c_list = ["#271f30","#6c5a49","#c8ad55","#9bc59d","#d0fcb3"]
#c_list.reverse()
# for i in range(len(c_list)):
# if c_list[i][0]!= "#":
# c_list[i] = "#" + c_list[i]
print(c_list)
c_map = mcolors.ListedColormap(c_list)
fig, ax = plt.subplots(figsize=(10,10))
ax = df_geo.plot(ax=ax, column = "desnidade_pop",
scheme="quantiles",
cmap=c_map,
legend=True,
legend_kwds={"title": "Habitantes por km²"}
)
['#271f30', '#6c5a49', '#c8ad55', '#9bc59d', '#d0fcb3']
Filtrando mapa por valor de coluna¶
In [23]:
Copied!
fltr = df_geo["NM_MUN"] == "Salvador"
df_geo_ssa = df_geo[fltr]
df_geo_ssa.shape, df_geo.shape
fltr = df_geo["NM_MUN"] == "Salvador"
df_geo_ssa = df_geo[fltr]
df_geo_ssa.shape, df_geo.shape
Out[23]:
((4552, 31), (30642, 31))
In [24]:
Copied!
df_geo_ssa.info()
df_geo_ssa.info()
<class 'geopandas.geodataframe.GeoDataFrame'> Int64Index: 4552 entries, 20719 to 25270 Data columns (total 31 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 CD_SETOR 4552 non-null object 1 AREA_KM2 4552 non-null float64 2 CD_REGIAO 4552 non-null object 3 NM_REGIAO 4552 non-null object 4 CD_UF 4552 non-null object 5 NM_UF 4552 non-null object 6 CD_MUN 4552 non-null object 7 NM_MUN 4552 non-null object 8 CD_DIST 4552 non-null object 9 NM_DIST 4552 non-null object 10 CD_SUBDIST 4552 non-null object 11 NM_SUBDIST 4552 non-null object 12 CD_MICRO 4552 non-null object 13 NM_MICRO 4552 non-null object 14 CD_MESO 4552 non-null object 15 NM_MESO 4552 non-null object 16 CD_RGI 4552 non-null object 17 NM_RGI 4552 non-null object 18 CD_RGINT 4552 non-null object 19 NM_RGINT 4552 non-null object 20 CD_CONCURB 4552 non-null object 21 NM_CONCURB 4552 non-null object 22 v0001 4552 non-null float64 23 v0002 4552 non-null float64 24 v0003 4552 non-null float64 25 v0004 4552 non-null float64 26 v0005 4552 non-null float64 27 v0006 4552 non-null float64 28 v0007 4552 non-null float64 29 geometry 4552 non-null geometry 30 desnidade_pop 4552 non-null float64 dtypes: float64(9), geometry(1), object(21) memory usage: 1.1+ MB
In [25]:
Copied!
df_geo_ssa.plot()
df_geo_ssa.plot()
Out[25]:
<Axes: >
In [26]:
Copied!
df_geo_ssa.crs
df_geo_ssa.crs
Out[26]:
<Geographic 2D CRS: EPSG:4326> Name: WGS 84 Axis Info [ellipsoidal]: - Lat[north]: Geodetic latitude (degree) - Lon[east]: Geodetic longitude (degree) Area of Use: - name: World. - bounds: (-180.0, -90.0, 180.0, 90.0) Datum: World Geodetic System 1984 ensemble - Ellipsoid: WGS 84 - Prime Meridian: Greenwich
In [27]:
Copied!
df_geo_ssa = df_geo_ssa.to_crs("31984")
df_geo_ssa.crs
df_geo_ssa = df_geo_ssa.to_crs("31984")
df_geo_ssa.crs
Out[27]:
<Projected CRS: EPSG:31984> Name: SIRGAS 2000 / UTM zone 24S Axis Info [cartesian]: - E[east]: Easting (metre) - N[north]: Northing (metre) Area of Use: - name: Brazil - between 42°W and 36°W, northern and southern hemispheres, onshore and offshore. - bounds: (-42.0, -26.35, -36.0, 0.74) Coordinate Operation: - name: UTM zone 24S - method: Transverse Mercator Datum: Sistema de Referencia Geocentrico para las AmericaS 2000 - Ellipsoid: GRS 1980 - Prime Meridian: Greenwich
Gravando Geojson¶
In [28]:
Copied!
with open("SSA_BA_Malha_Preliminar_2022.json" , 'w') as file:
file.write(df_geo_ssa.to_json())
with open("SSA_BA_Malha_Preliminar_2022.json" , 'w') as file:
file.write(df_geo_ssa.to_json())
Abrindo GeoJson¶
In [29]:
Copied!
df_2 = gp.read_file("SSA_BA_Malha_Preliminar_2022.json")
df_2.info()
df_2 = gp.read_file("SSA_BA_Malha_Preliminar_2022.json")
df_2.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 4552 entries, 0 to 4551 Data columns (total 32 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 id 4552 non-null object 1 CD_SETOR 4552 non-null object 2 AREA_KM2 4552 non-null float64 3 CD_REGIAO 4552 non-null object 4 NM_REGIAO 4552 non-null object 5 CD_UF 4552 non-null object 6 NM_UF 4552 non-null object 7 CD_MUN 4552 non-null object 8 NM_MUN 4552 non-null object 9 CD_DIST 4552 non-null object 10 NM_DIST 4552 non-null object 11 CD_SUBDIST 4552 non-null object 12 NM_SUBDIST 4552 non-null object 13 CD_MICRO 4552 non-null object 14 NM_MICRO 4552 non-null object 15 CD_MESO 4552 non-null object 16 NM_MESO 4552 non-null object 17 CD_RGI 4552 non-null object 18 NM_RGI 4552 non-null object 19 CD_RGINT 4552 non-null object 20 NM_RGINT 4552 non-null object 21 CD_CONCURB 4552 non-null object 22 NM_CONCURB 4552 non-null object 23 v0001 4552 non-null float64 24 v0002 4552 non-null float64 25 v0003 4552 non-null float64 26 v0004 4552 non-null float64 27 v0005 4552 non-null float64 28 v0006 4552 non-null float64 29 v0007 4552 non-null float64 30 desnidade_pop 4552 non-null float64 31 geometry 4552 non-null geometry dtypes: float64(9), geometry(1), object(22) memory usage: 1.1+ MB
In [30]:
Copied!
df_2.plot()
df_2.plot()
Out[30]:
<Axes: >
Eliminando feição indesejada¶
Identificando feição indesejada -método 1¶
In [31]:
Copied!
df_2['coords'] = df_2['geometry'].apply(lambda x: x.representative_point().coords[0])
df_2['coords'] = df_2['geometry'].apply(lambda x: x.representative_point().coords[0])
In [32]:
Copied!
df_2['coords']
df_2['coords']
Out[32]:
0 (555517.6892997203, 8561162.794243902)
1 (555869.385196075, 8561221.765203156)
2 (555561.692228948, 8561448.0105288)
3 (555666.401386929, 8561893.694598991)
4 (555818.1373583635, 8561625.594414245)
...
4547 (554137.1694208445, 8563500.747517455)
4548 (551078.8695353717, 8562426.471542083)
4549 (551215.1880186847, 8562493.736728266)
4550 (552074.8722883032, 8564677.217530191)
4551 (551955.4441563855, 8564454.894890044)
Name: coords, Length: 4552, dtype: object
In [33]:
Copied!
df_2.plot()
for idx, row in df_2.iterrows():
plt.annotate(text=row['id'], xy=row['coords'],
horizontalalignment='center')
df_2.plot()
for idx, row in df_2.iterrows():
plt.annotate(text=row['id'], xy=row['coords'],
horizontalalignment='center')
Identificando feição indesejada - médodo 2¶
In [34]:
Copied!
df_2['AREA_KM2'].max()
df_2['AREA_KM2'].max()
Out[34]:
386.114232
In [35]:
Copied!
fltr = df_2['AREA_KM2'] == df_2['AREA_KM2'].max()
df_2[fltr].plot()
df_2[fltr].shape, df_2[fltr]["id"].values
fltr = df_2['AREA_KM2'] == df_2['AREA_KM2'].max()
df_2[fltr].plot()
df_2[fltr].shape, df_2[fltr]["id"].values
Out[35]:
((1, 33), array(['21881'], dtype=object))
Eliminado feição indesejada¶
In [36]:
Copied!
fltr = df_2["id"] != "21881"
df_2 = df_2[fltr]
fltr = df_2["id"] != "21881"
df_2 = df_2[fltr]
Gerando mapa
In [37]:
Copied!
fig, ax = plt.subplots(1)
df_2.plot(ax = ax, column="NM_SUBDIST" ,cmap="cubehelix", legend=True, legend_kwds={'bbox_to_anchor': (1.5, 1)})
fig, ax = plt.subplots(1)
df_2.plot(ax = ax, column="NM_SUBDIST" ,cmap="cubehelix", legend=True, legend_kwds={'bbox_to_anchor': (1.5, 1)})
Out[37]:
<Axes: >
Agregando com dissolve¶
https://geopandas.org/en/stable/docs/user_guide/aggregation_with_dissolve.html
In [38]:
Copied!
df_3 = df_2[['NM_SUBDIST', "v0001",'v0005', "geometry"]]
df_3 = df_3.dissolve(by='NM_SUBDIST', aggfunc='sum', as_index=False)
df_3.head()
df_3 = df_2[['NM_SUBDIST', "v0001",'v0005', "geometry"]]
df_3 = df_3.dissolve(by='NM_SUBDIST', aggfunc='sum', as_index=False)
df_3.head()
Out[38]:
| NM_SUBDIST | geometry | v0001 | v0005 | |
|---|---|---|---|---|
| 0 | Amaralina | POLYGON ((555768.884 8561020.182, 555765.446 8... | 254133.0 | 1138.743352 |
| 1 | Brotas | POLYGON ((554383.205 8563533.513, 554358.146 8... | 178577.0 | 900.154859 |
| 2 | Conceição da Praia | POLYGON ((552582.398 8565306.142, 552579.429 8... | 416.0 | 4.270202 |
| 3 | Itapoã | POLYGON ((563322.057 8565454.801, 563258.583 8... | 191205.0 | 805.219044 |
| 4 | Mares | POLYGON ((553634.123 8569419.347, 553605.637 8... | 3314.0 | 37.887135 |
In [39]:
Copied!
fig, ax = plt.subplots(1)
df_3.plot(ax = ax,column="NM_SUBDIST", cmap="cubehelix", legend=True, legend_kwds={'bbox_to_anchor': (1.5, 1)})
plt.xticks(rotation=90)
fig, ax = plt.subplots(1)
df_3.plot(ax = ax,column="NM_SUBDIST", cmap="cubehelix", legend=True, legend_kwds={'bbox_to_anchor': (1.5, 1)})
plt.xticks(rotation=90)
Out[39]:
(array([535000., 540000., 545000., 550000., 555000., 560000., 565000.,
570000., 575000., 580000.]),
[Text(535000.0, 0, '535000'),
Text(540000.0, 0, '540000'),
Text(545000.0, 0, '545000'),
Text(550000.0, 0, '550000'),
Text(555000.0, 0, '555000'),
Text(560000.0, 0, '560000'),
Text(565000.0, 0, '565000'),
Text(570000.0, 0, '570000'),
Text(575000.0, 0, '575000'),
Text(580000.0, 0, '580000')])
In [59]:
Copied!
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='flare',legend=True )
cx.add_basemap(ax=ax, crs=df_2.crs)
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='flare',legend=True )
cx.add_basemap(ax=ax, crs=df_2.crs)
In [ ]:
Copied!
# Listas de provedores de mapas online
cx.providers
# Listas de provedores de mapas online
cx.providers
In [76]:
Copied!
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='flare',legend=True )
cx.add_basemap(ax=ax, source=cx.providers.CartoDB.Voyager , crs=df_2.crs)
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='flare',legend=True )
cx.add_basemap(ax=ax, source=cx.providers.CartoDB.Voyager , crs=df_2.crs)
In [41]:
Copied!
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='OrRd',legend=True )
cx.add_basemap(ax, source=cx.providers.CartoDB.PositronNoLabels, zoom=12, crs=df_2.crs)
cx.add_basemap(ax, source=cx.providers.CartoDB.PositronOnlyLabels, zoom=15, crs=df_2.crs)
fig, ax = plt.subplots(1, figsize=(10,10))
df_2.plot(ax = ax, column="v0001", cmap='OrRd',legend=True )
cx.add_basemap(ax, source=cx.providers.CartoDB.PositronNoLabels, zoom=12, crs=df_2.crs)
cx.add_basemap(ax, source=cx.providers.CartoDB.PositronOnlyLabels, zoom=15, crs=df_2.crs)
Marcando um ponto por corrdenadas¶
In [44]:
Copied!
from shapely.geometry import Point
# substitua os valores de latitue e longitude pelos valores do seu ponto
# use pontos para separar os decimais
lat = 0
lon = 0
pt_terreno = Point(lon, lat)
from shapely.geometry import Point
# substitua os valores de latitue e longitude pelos valores do seu ponto
# use pontos para separar os decimais
lat = 0
lon = 0
pt_terreno = Point(lon, lat)
aplicando sistema de coordenads
In [45]:
Copied!
loc_terreno= gp.GeoDataFrame([1], geometry=[pt_terreno], crs="EPSG:4326")
loc_terreno= gp.GeoDataFrame([1], geometry=[pt_terreno], crs="EPSG:4326")
In [46]:
Copied!
loc_terreno.head()
loc_terreno.head()
Out[46]:
| 0 | geometry | |
|---|---|---|
| 0 | 1 | POINT (-38.43202 -12.97391) |
In [47]:
Copied!
loc_terreno = loc_terreno.to_crs(df_2.crs)
loc_terreno = loc_terreno.to_crs(df_2.crs)
In [48]:
Copied!
fig, ax = plt.subplots()
df_2.plot(ax=ax, cmap="Oranges")
loc_terreno.plot(ax=ax)
plt.xticks(rotation=90)
fig, ax = plt.subplots()
df_2.plot(ax=ax, cmap="Oranges")
loc_terreno.plot(ax=ax)
plt.xticks(rotation=90)
Out[48]:
(array([535000., 540000., 545000., 550000., 555000., 560000., 565000.,
570000., 575000., 580000.]),
[Text(535000.0, 0, '535000'),
Text(540000.0, 0, '540000'),
Text(545000.0, 0, '545000'),
Text(550000.0, 0, '550000'),
Text(555000.0, 0, '555000'),
Text(560000.0, 0, '560000'),
Text(565000.0, 0, '565000'),
Text(570000.0, 0, '570000'),
Text(575000.0, 0, '575000'),
Text(580000.0, 0, '580000')])
In [49]:
Copied!
entorno = loc_terreno.buffer(1000)
entorno = loc_terreno.buffer(1000)
In [77]:
Copied!
fig, ax = plt.subplots()
plt.grid(alpha = .2)
df_2.plot(ax=ax, cmap="Oranges")
entorno.plot(ax=ax)
plt.xticks(rotation=90)
fig.show()
fig, ax = plt.subplots()
plt.grid(alpha = .2)
df_2.plot(ax=ax, cmap="Oranges")
entorno.plot(ax=ax)
plt.xticks(rotation=90)
fig.show()
In [54]:
Copied!
fltr = df_2.intersects(entorno[0])
df_4 = df_2[fltr]
fltr = df_2.intersects(entorno[0])
df_4 = df_2[fltr]
In [57]:
Copied!
fig, ax = plt.subplots()
df_4.plot(ax=ax, cmap="Oranges")
loc_terreno.plot(ax=ax, marker='o', color='teal', markersize=100)
ax.annotate("Terreno", xy= (loc_terreno.geometry.x, loc_terreno.geometry.y), xytext=(3, 3), textcoords="offset points")
plt.xticks(rotation=90)
ax.ticklabel_format(style='plain')
#salvando figura
fig.savefig('./entorno.svg')
fig.show()
fig, ax = plt.subplots()
df_4.plot(ax=ax, cmap="Oranges")
loc_terreno.plot(ax=ax, marker='o', color='teal', markersize=100)
ax.annotate("Terreno", xy= (loc_terreno.geometry.x, loc_terreno.geometry.y), xytext=(3, 3), textcoords="offset points")
plt.xticks(rotation=90)
ax.ticklabel_format(style='plain')
#salvando figura
fig.savefig('./entorno.svg')
fig.show()